<template>
	<div class="addProject business-workAdd">
		<div class="addForm zll-form">
			<div class="top_search">
				<span @click="cutYear()" class="el_icons el-icon-caret-left"></span>
				<span class="year">{{ currentYear }}</span>
				<span @click="plusYear()" class="el_icons el-icon-caret-right"></span>
			</div>
			<div class="main_contain" v-loading="tableLoading">
				<div v-if="tableList.length > 0">
					<div class="_middle">
						<div class="li_list">
							<p class="tops"></p>
							<p>白班</p>
							<p>夜班</p>
							<p>合计</p>
						</div>
						<div class="li_list" v-for="(item,index) in tableList" :key="index">
							<p class="tops">{{ item.moth }}</p>
							<p>{{ item.baibanValue }}</p>
							<p>{{ item.yebanValue }}</p>
							<p>{{ item.totalValue }}</p>
						</div>
					</div>
					<div class="chart_bar" ref="chart"></div>
				</div>
				<div v-else class="no_search no_data">
					<img src="@/assets/back_manage_img/fenxi_nodata.png" alt="">
					<p>很抱歉，查不到您想要的数据</p>
				</div>
			</div>
		</div>
	</div>
</template>
<script>

	import {getStore} from "@/plugins/localStore";
	import {formatDate} from "@/plugins/formatDate";
	import echartOption from './echart'

	export default {
		data() {
			return {
				currentYear: '',
				tableList: [],
				tableLoading:false
			}
		},
		methods: {
			getList() {
				let self = this;
				self.tableList = [];
				self.tableLoading = true;
				self.$http({
					url: "/jinl/abandonHandle/getAbandonYearVoList",
					method: "post",
					params:{year:self.currentYear}
				}).then(resp => {
					if (resp.success) {
						self.tableList = resp.result;
					}
					if(self.tableList.length > 0){
						self.$nextTick(()=>{
							self.getEchartData();
						});

					}
					self.tableLoading = false;
				});
			},
			cutYear() {
				this.currentYear = (parseInt(this.currentYear) -1)+'';
				this.getList();
			},
			plusYear() {
				this.currentYear = (parseInt(this.currentYear) +1)+'';
				this.getList();
			},

			getEchartData() {
				let self = this;
				let echart = self.$echarts.init(self.$refs.chart);
				let option = echartOption.option;
				option.title.text = self.currentYear+'年度废料数据分析';
				let datas = [];
				for(let d of self.tableList){
					let totalValue = parseFloat(d.totalValue);
					datas.push(totalValue);
				}
				option.series[0].data = datas;
				echart.setOption(option);
			}
		},
		mounted() {
			this.currentYear = formatDate(new Date(), 'yyyy');
			this.getList();
		},
		components: {},
	}
</script>
<style lang="scss" scoped>
	@import "@/style/dialog.scss";

	.top_search {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 15px;

		.el_icons {
			font-size: 24px;
			color: #8a8a8a;
			cursor: pointer;
			margin: 0 10px;

			&:hover {
				color: #00D1D0;
			}
		}

		.year {
			width: 120px;
			border: 1px solid #cecece;
			border-radius: 5px;
			height: 26px;
			line-height: 26px;
			text-align: center;
		}
	}

	.chart_bar {
		height: 250px;
		margin-top: 20px;
		border: 1px solid #d55e09;
		background: #ffe3cc;
	}

	._middle {
		display: flex;
		width: 100%;
		border-top: 1px solid #cecece;
		border-left: 1px solid #cecece;

		.li_list {
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;

			.tops {
				background: #ddd;
				color: #8a8a8a;
			}

			p {
				width: 100%;
				text-align: center;
				line-height: 26px;
				height: 26px;
				border-bottom: 1px solid #cecece;
				border-right: 1px solid #cecece;
			}
		}
	}

	.main_contain {
		.tableList {
			td, th {
				height: 25px !important;
				line-height: 25px !important;
			}
		}

		.no_search {
			width: 100%;
			height: 200px;
			color: #8a8a8a;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			img {
				width: 50px;
				margin-bottom: 10px;
			}
		}

		.no_data {
			color: #4d91aa;
		}
	}
</style>